import numpy as np
import tensorflow as tf
import random


def parse_anchors(anchor_path):
    '''
    获取anchors
    returned data: shape [N, 2], dtype float32
    '''
    anchors = np.reshape(np.asarray(open(anchor_path, 'r').read().strip().split(','), np.float32), [-1, 2])
    return anchors


def read_class_names(class_name_path):
    names = {}
    with open(class_name_path, 'r') as data:
        for ID, name in enumerate(data):
            names[ID] = name.strip('\n')
    return names


if __name__ == "__main__":
    # 指定classes路径
    data_path = '/Users/yaoxiaoying/Desktop/yoloV3-tf2/config/classname'
    classname  = read_class_names(data_path)
    print(len(classname))
    anchor_path = '/Users/yaoxiaoying/Desktop/yoloV3-tf2/config/anchor'
    anchors= parse_anchors(anchor_path)
    print(anchors)


